package com.redeemer150.oj.judge;




import com.redeemer150.oj.judge.codesanbox.model.JudgeInfo;
import com.redeemer150.oj.judge.strategy.DefaultJudgeStrategy;
import com.redeemer150.oj.judge.strategy.JavaLanguageJudgeStrategy;
import com.redeemer150.oj.judge.strategy.JudgeContext;
import com.redeemer150.oj.judge.strategy.JudgeStrategy;
import com.redeemer150.oj.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * @author 炼金术士
 * @version 1.0
 * @description: 根据判题上下文匹配对应的判题策略,并进行判题
 * @date 2025/5/20 14:14
 */

@Service
public class JudgeManager {

// 判断题目
    JudgeInfo doJudge(JudgeContext judgeContext){
        // 获取提交的题目
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        // 获取提交的编程语言
        String language = questionSubmit.getLanguage();
        // 创建默认的判断策略
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        // 如果提交的编程语言是java，则创建Java语言的判断策略
        if("java".equals(language)){
            judgeStrategy=new JavaLanguageJudgeStrategy();
        }
        // 执行判断
        return judgeStrategy.doJudge(judgeContext);

    }
}
